<template>
  <div class="menu-wrapper" :class="{ 'menu-expanded': menuExpanded }">
    <div class="menu-toggle" @click="toggleMenu">
      <div class="menu-icon">
        <span></span>
        <span></span>
        <span></span>
      </div>
    </div>

    <yk-space dir="vertical" class="menu-bar" size="m">
      <router-link :to="item.path" v-for="item in navLinks" :key="item.path" class="menu-bar__nav"
        @click="menuExpanded = false">
        <yk-space align="center" size="m">
          <component :is="item.icon" class="nav-icon"></component>
          <yk-text class="nav-text">{{ item.name }}</yk-text>
        </yk-space>
      </router-link>
    </yk-space>
  </div>
</template>

<script setup lang="ts">
import { navLinks } from '@/utils/menu';
import { ref } from 'vue';

const menuExpanded = ref(false);
const toggleMenu = () => {
  menuExpanded.value = !menuExpanded.value;
};
</script>

<style lang="less" scoped>
// 定义变量
@transition-speed: 0.3s;
@menu-bg: rgba(255, 255, 255, 0.95);
@menu-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
@active-color: #3a7bd5;
@active-gradient: linear-gradient(to right, #3a7bd5, #4898e6);
@hover-bg: #f5f7fa;
@text-color: #2c3e50;
@icon-color: #8492a6;
@mobile-breakpoint: 768px;
@tablet-breakpoint: 1024px;

// 菜单容器
.menu-wrapper {
  position: relative;
  z-index: 100;
}

// 切换按钮
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 101;
  cursor: pointer;
  align-items: center;
  justify-content: center;

  .menu-icon {
    width: 24px;
    height: 18px;
    position: relative;

    span {
      position: absolute;
      left: 0;
      width: 100%;
      height: 2px;
      background-color: @text-color;
      border-radius: 2px;
      transition: all @transition-speed ease;

      &:nth-child(1) {
        top: 0;
      }

      &:nth-child(2) {
        top: 8px;
      }

      &:nth-child(3) {
        top: 16px;
      }
    }
  }

  .menu-expanded & {
    .menu-icon {
      span {
        &:nth-child(1) {
          transform: rotate(45deg);
          top: 8px;
        }

        &:nth-child(2) {
          opacity: 0;
        }

        &:nth-child(3) {
          transform: rotate(-45deg);
          top: 8px;
        }
      }
    }
  }
}

// 主菜单样式
.menu-bar {
  padding: 16px;
  position: fixed;
  top: 72px;
  left: 8px;
  background: @menu-bg;
  border-radius: 12px;
  box-shadow: @menu-shadow;
  transition: transform @transition-speed ease;

  &__nav {
    width: 160px;
    height: 42px;
    border-radius: 8px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: all 0.2s ease;

    .nav-icon {
      color: @icon-color;
      width: 18px;
      height: 18px;
      transition: all 0.2s ease;
    }

    .nav-text {
      color: @text-color;
      font-size: 15px;
      transition: all 0.2s ease;
    }

    &:hover {
      background: @hover-bg;
      transform: translateX(4px);

      .nav-text {
        font-weight: 500;
      }

      .nav-icon {
        color: @active-color;
      }
    }
  }

  .router-link-active {
    background: @active-gradient;
    box-shadow: 0 4px 12px rgba(58, 123, 213, 0.3);
    transform: translateX(4px);

    .nav-icon {
      color: white;
    }

    .nav-text {
      color: white;
      font-weight: 500;
    }

    &:hover {
      background: @active-gradient;
      transform: translateX(4px) scale(1.02);
    }
  }
}

// 响应式设计
@media (max-width: @tablet-breakpoint) {
  .menu-bar {
    top: 64px;
    left: 8px;
    padding: 12px;

    &__nav {
      width: 140px;
      height: 38px;

      .nav-text {
        font-size: 14px;
      }
    }
  }
}

@media (max-width: @mobile-breakpoint) {
  .menu-toggle {
    display: flex;
  }

  .menu-bar {
    top: 16px;
    left: 16px;
    padding: 60px 12px 16px;
    transform: translateX(-200px);
    box-shadow: @menu-shadow;

    .menu-expanded & {
      transform: translateX(0);
    }

    &__nav {
      width: 160px;
      margin-bottom: 4px;
    }
  }
}
</style>